# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=cereal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.2
pkgrel=1
pkgdesc="A C++11 library for serialization (mingw-w64)"
arch=('any')
url="https://uscilab.github.io/cereal/"
license=('New BSD license')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-boost")
checkdepends=("${MINGW_PACKAGE_PREFIX}-gflags")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/USCiLab/cereal/archive/v${pkgver}.tar.gz"
        "${_realname}-1.2.2.patch"
        "build-fixes.patch")
sha256sums=('1921f26d2e1daf9132da3c432e2fd02093ecaedf846e65d7679ddf868c7289c4'
            '5454976ffdc81051f59065431998fcfc717d8b4489f39c212c3d06ae52746306'
            '9d2ae6a04d9b3773f2f6c5344d79d9554306a871fc2a1aa763ac1d2e377042ff')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/${_realname}-1.2.2.patch"
  patch -Np1 -i "${srcdir}/build-fixes.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "../${_realname}-${pkgver}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
